package com.teradata.webmvc.controller;

import net.bytebuddy.utility.RandomString;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "test", urlPatterns = "/test/*")
public class MyServlet extends HttpServlet {
    @Override
    public void service(HttpServletRequest req,final HttpServletResponse resp) throws ServletException, IOException {

        String loclAddr = req.getLocalAddr();
        String remoteAddr = req.getRemoteAddr();


        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(500);
                    resp.getWriter().write("hello:" + RandomString.make() + " local:" + loclAddr + " remote:" + remoteAddr);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });

        thread.start();


    }
}
